import cheerio from 'cheerio'
import to from '@/utils/to'
import fetch from '@/utils/request'
import {requestText} from '@/utils/request'
class SpiderService {
    static async demo(url) {
        let htmlStr = await requestText(url, {})
        // let htmlStr = await req.text()
        const $ = cheerio.load(htmlStr, {
            ignoreWhitespace: true, // 是否忽略空白符 attribs:
        }); //用cheerio解析页面数据 $.root().find('*')
        let list = []
        $.root().find('li').each(function (item, index) {
            let title = $(this).text()
            list.push({
                title
            })
        })
        return {
            code: 200,
            msg: '爬虫爬取成功',
            data: list
        }
    }
}
export default SpiderService